from base_utils.response_http_code import (
    BadRequestStatus,
    NotFoundStatus,
    ForbiddenStatus,
    SuccessStatus,
    ServerErrorStatus,
    AuthenticateStatus,
)


class BaseError(Exception):
    # 默认状态码
    status_code: SuccessStatus = None

    def __init__(self, msg: str = None, status_code: SuccessStatus = None):
        if not status_code:
            # 没有传递，就使用类的status_code变量
            status_code = self.status_code
        # 设置好响应码
        self.http_code = status_code.http_code
        # 设置好响应内容
        self.msg = msg or status_code.msg
        super().__init__(self.msg)


# 参数问题
class ParamsError(BaseError):
    status_code = BadRequestStatus
    msg = BadRequestStatus.msg


# 资源找不到
class ResourceNotFoundError(BaseError):
    status_code = NotFoundStatus
    msg = NotFoundStatus.msg


# 系统内部问题
class ServiceError(BaseError):
    status_code = ServerErrorStatus
    msg = ServerErrorStatus.msg


# 权限问题
class ForbiddenError(BaseError):
    status_code = ForbiddenStatus
    msg = ForbiddenStatus.msg


# 认证问题
class AuthenticateError(BaseError):
    status_code = AuthenticateStatus
    msg = AuthenticateStatus.msg


if __name__ == "__main__":

    error = ServiceError()
    print(error.http_code, error.msg)
    error1 = ServiceError("1111")
    print(error1.http_code, error1.msg)
